package com.androider.timememory.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.content.Context;
import android.content.res.Resources;

import com.androider.timememory.R;

public class StringUtil {
    
    /**
     * Get the formated date
     * yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static String getCurrnetDate(String format){
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(new Date()).toString();
    }
    
    /**
     * Get the date only
     * @param date full datetime
     * @return
     */
    public static String getDate(String date) {
        int pos = date.indexOf(" ");
        if(pos != -1) {
            return date.substring(0, pos + 1);
        }
        return date;
    }
    
    /**
     * Get the head title of each page.
     * @param context
     * @return
     */
    public static ArrayList<String> getTitles(Context context) {
		ArrayList<String> titles = new ArrayList<String>();
		Resources res = context.getResources();
		for(String s : res.getStringArray(R.array.titles)) {
			titles.add(s);
		}
		return titles;
	}
    
    /**
     * Remove the CharSequence "+86" or "-" in the number string.
     * @param number
     * @return
     */
    public static String trimNumber(String number) {
    	number = number.trim();
    	number = number.replace("+86", "");
    	number = number.replace("-", "");
        return number;
    }
}
